<template>
  <div class="page-container">
    <div class="body-container">
      <div class="content-container">
        <div class="nav-container">
          <img :src="searchNav" />
        </div>
        <div class="search-container">
          <img :src="searchIcon" />
          <span>搜索文章</span>
          <input
            v-model="searchValue"
            @input="inputSearch"
            @keyup.enter="searchList"
          />
          <i
            class="clearinput iconfont iconcancel-1-copy"
            v-show="clearinput"
            @click="valueDel"
          ></i>
          <i class="searchinput iconfont iconsousuo" @click="searchList"></i>
        </div>

        <div class="newessay-container">
          <div
            ref="list"
            v-for="(item, index) of eachList"
            :key="index"
            class="essay-list animate__animated animate__bounceInUp"
          >
            <div class="content-text">
              <div class="titleWrapper">
                <h1 @click="targetEssay(item.id)">
                  {{ item.title }}
                </h1>
              </div>
              <div class="introWrapper">{{ item.intro }}</div>
              <div class="infoWrapper">
                <div class="type-icon">
                  <i class="iconfont iconleixing"></i>
                  <span>{{ item.type.typename }}</span>
                </div>
                <div class="date-icon">
                  <i class="iconfont iconshijian"></i>
                  <span>{{ item.createdAt | formtTime }}</span>
                </div>
                <div class="target-icon" @click="targetEssay(item.id)">
                  <i class="iconfont iconhuaban1"></i>
                  <span>查看详情</span>
                </div>
              </div>
            </div>
            <div class="content-img">
              <img v-lazy="item.type.typeimg" />
            </div>
          </div>

          <div class="loader" v-show="showMore"></div>
          <div class="load-more-none" v-show="isNone">--没有搜索到该结果--</div>
        </div>

        <go-top :has-outline="false" :right="40"></go-top>
      </div>
    </div>
  </div>
</template>

<script>
import GoTop from "@inotom/vue-go-top";
import ApiService from "@/service/index";
import { formtTime } from "@/utils/tools";
import { NAV_PHOTO, SEARCH_ICON } from "@/config/config";
const api = new ApiService();
export default {
  name: "SearchViews",
  filters: {
    formtTime
  },
  components: {
    GoTop
  },
  async created() {
    this.essayList = await api.findEssayAll();
  },
  data() {
    return {
      searchNav: NAV_PHOTO.search,
      searchIcon: SEARCH_ICON,
      searchValue: "",
      isNone: false,
      clearinput: false,
      showMore: false,
      essayList: [],
      eachList: []
    };
  },
  methods: {
    targetEssay(id) {
      if (id) this.$router.push({ path: "essay", query: { originid: id } });
    },
    inputSearch() {
      if (this.searchValue !== "") {
        this.clearinput = true;
        return;
      }

      this.clearinput = false;
    },
    valueDel() {
      this.searchValue = "";
      this.clearinput = false;
    },
    searchList() {
      if (this.searchValue) {
        this.showMore = true;
        this.eachList = this.essayList.filter(item => {
          return item.title.indexOf(this.searchValue) !== -1;
        });
        if (this.eachList.length <= 0) {
          this.isNone = true;
        } else {
          this.isNone = false;
        }
        this.showMore = false;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
$theme: #f2db4d;
.loader {
  font-size: 15px;
  width: 1em;
  height: 1em;
  line-height: 15px;
  border-radius: 50%;
  margin: 90px auto;
  text-indent: -9999em;
  animation: load-effect 1s infinite linear;
}
@keyframes load-effect {
  0% {
    box-shadow: -3em 2em 0 0.5em $theme, 0 2em 0 0 $theme,
      3em 2em 0 -0.5em $theme;
  }
  25% {
    box-shadow: -3em 2em 0 0 $theme, 0 2em 0 -0.5em $theme, 3em 2em 0 0 $theme;
  }
  50% {
    box-shadow: -3em 2em 0 -0.5em $theme, 0 2em 0 0 $theme,
      3em 2em 0 0.5em $theme;
  }
  75% {
    box-shadow: -3em 2em 0 0 $theme, 0 2em 0 0.5em $theme, 3em 2em 0 0 $theme;
  }
  100% {
    box-shadow: -3em 2em 0 0.5em $theme, 0 2em 0 0 $theme,
      3em 2em 0 -0.5em $theme;
  }
}
.body-container {
  width: 100%;
  height: 100%;
}

.content-container {
  width: 1305px;
  height: 100%;
  margin: 0 auto;
  .nav-container {
    width: 102px;
    height: 99px;
    margin-top: 70px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .search-container {
    width: 100%;
    height: 50px;
    line-height: 50px;
    margin-top: 50px;
    position: relative;
    img {
      position: absolute;
      top: 12px;
      width: 28px;
      height: 28px;
    }
    span {
      height: 50px;
      line-height: 50px;
      margin-left: 41px;
    }
    input {
      width: 1125px;
      height: 44px;
      border-radius: 35px;
      margin-left: 25px;
      background: none;
      outline: none;
      padding-left: 20px;
    }
    input:focus {
      border: 2px solid $theme;
    }
    .clearinput {
      font-size: 20px;
      position: absolute;
      top: 1px;
      right: 90px;
      cursor: pointer;
    }
    .searchinput {
      font-size: 25px;
      position: absolute;
      top: 1px;
      right: 50px;
      cursor: pointer;
    }
  }
  .newessay-container {
    width: 100%;
    height: 100%;
    min-height: 300px;
    .essay-list {
      width: 1253px;
      height: 233px;
      margin: 0 auto;
      box-shadow: #999 0px 0px 10px;
      margin-top: 55px;
      .content-text {
        float: left;
        width: 863px;
        .titleWrapper {
          h1 {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            cursor: pointer;
          }
          padding: 30px;
        }
        .introWrapper {
          font-size: 18px;
          margin-left: 35px;
        }
        .infoWrapper {
          padding-left: 400px;
          padding-top: 35px;
          position: relative;
          .type-icon {
            float: left;
            i {
              padding-right: 5px;
            }
          }
          .date-icon {
            margin-left: 30px;
            float: left;
            i {
              padding-right: 5px;
            }
          }
          .target-icon {
            float: left;
            position: absolute;
            right: 50px;
            top: 30px;
            width: 110px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            border-radius: 9px;
            background-color: $theme;
            margin-left: 30px;
            color: #fff;
            cursor: pointer;
            i {
              padding-right: 5px;
            }
          }
        }
      }
      .content-img {
        float: left;
        width: 390px;
        height: 233px;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
.load-more-none {
  width: 100%;
  text-align: center;
  margin-top: 90px;
}
</style>